<template>
	<view class="content reg-page">
		<view class="input-group">
			<view class="input-row border-bottom-1px">
				<text class="title">求职类型</text>
				<radio-group @change="changeRadio" class="row">
					<label class="uni-list-cell uni-list-cell-pd row margin-right-20" v-for="(item, index) in items" :key="index">
						<view><radio color="#84C0F4" :value="item.dictValue" :checked="item.dictValue==jobDetail.jobType" /></view>
						<view>{{ item.dictValue }}</view>
					</label>
				</radio-group>
			</view>
			<view class="input-column border-bottom-1px" @click="toPost(1,jobDetail.professionName)">
				<text class="title">期望职位</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请选择期望职位" :value="jobDetail.professionName" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px" @click="toIndustry(1)">
				<text class="title">期望行业</text>
				<view class="space-between-algin row padding-height-20">
					<input class="padding-10" disabled="true" placeholder="请选择期望行业" :value="jobDetail.industryName||'不限'" style="width:404rpx;" />
					<text class="yzb yzb-next"></text>
				</view>
			</view>
			<view class="input-column border-bottom-1px">
				<text class="title">薪资要求</text>
				<view class="picker">
					<picker @change="bindPickerChange" :value="salaryIndex" range-key="dictValue" :range="salaeyArray">
						<input placeholder="请选择薪资要求" disabled :value="jobDetail.salaryRang" />
					</picker>
					<text class="yzb yzb-next"></text>
				</view>
			</view>
		</view>
		<view class="btn-row row flex jcsb">
			<button  type="warn" v-if="expJobId" class="btn-delete" @tap="remove(expJobId)">删除</button><!--  有id显示-->
			<button type="primary" class="btn-save" :class="expJobId?'width-55':'width-90'" @tap="register(1)">保存</button>
		</view>
	</view>
</template>

<script>
import { mapState } from 'vuex';
import mInput from '@/components/m-input/m-input.vue';
import mCell from '@/components/m-cell/m-cell.vue';
import mpvuePicker from '@/components/mpvue-picker/mpvue-picker.vue';
import cityData from '@/common/cityData.js';
import graceChecker from '@/common/graceChecker.js';
import mCodedialog from '@/components/m-codedialog/m-codedialog.vue';
import formRuleConfig from '@/config/formRule.config.js';//表单校验
import config from "@/config/index.config.js";//地址
export default {
	components: {
		mInput,
		mCell,
		mpvuePicker,
		mCodedialog
	},
	computed: {
		...mapState(['openId', 'customerInfo'])
	},	
	data() {
		return {
			resumeId:'',
			expJobId:'',//职位id
			current:'',
			jobDetail:{
				professionId:'',//职位id
				professionName:'',//职位名称
				industryName:'',//行业名称
				industryIds:'',//行业id
				jobType:'',
			},			
			selectPost:{
				name:'',
				id:''
			},
			selectIndustrys:null,
			selectIndustryName:'不限',
			selectIndustryIds:'0',			
			items:[],//求职类型
			salaryValue: null,
			salaryIndex: 0,
			salaeyArray:[],
			index:'',//数组下标
		};
	},
	onLoad(query) {
		this.expJobId = query.expJobIds
		this.resumeId = query.resumeId
		if(this.expJobId){
			this.getDetailJob()
		}				
		this.getPositionType()//职位类型
		this.getSalary()//薪资范围
	},
	onShow() {
		//console.log(this.jobDetail)
	},
	methods: {		
		//详情
		async getDetailJob(){
			var that = this
			let res= await this.$apis.getDetailJob(this.expJobId);
			if(res.msg =="操作成功"){
				that.jobDetail = res.data				
			}
		},
		//获取求职类型
		async getPositionType(){
			var that = this
			let res= await this.$apis.getPositionType();
			if(res.code == 200){
				that.items = res.data
			}
		},
		//获取薪资范围		
		async getSalary(){
			var that = this
			let res= await this.$apis.getSalary();
			if(res.code == 200){
				that.salaeyArray = res.data
			}
		},
		//求职类型选择
		changeRadio(e){
			this.jobDetail.jobType = e.detail.value;
		},
		//期望行业
		toIndustry(choicetype) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.industry,
				query: {
					choicetype: choicetype
				}
			});
		},
		//职位选择
		toPost(type,professionName) {
			this.$mRouter.push({
				route: this.$mRoutesConfig.post,
				query: {
					Typevalue:type,
					slectName:professionName,
				}
			});
		},
		//求职类型选择
		radioChange: function(evt) {
			for (let i = 0; i < this.items.length; i++) {
				if (this.items[i].dictValue == evt.target.value) {
					console.log(this.items[i].dictValue)
					console.log(evt.target.value)
					this.jobDetail.jobType = evt.target.value
					
					break;
				}
			}		
		},
		//薪资范围
		bindPickerChange: function(e) {
			this.salaryIndex = e.target.value;
			this.jobDetail.salaryRang = this.salaeyArray[this.salaryIndex].dictValue;
		},
		// 点击保存按钮
		async register(type) {
			if(!this.jobDetail.jobType){
				uni.showToast({
					icon:'none',
					title:"请选择求职类型"
				})
				return;
			}			
			if(!this.jobDetail.professionId || !this.jobDetail.professionName){
				uni.showToast({
					icon:'none',
					title:"请选择期望职位"
				})
				return;
			}
			if(!this.jobDetail.industryName || !this.jobDetail.industryIds){
				uni.showToast({
					icon:'none',
					title:"请选择期望行业"
				})
				return;
			}
			if(!this.jobDetail.salaryRang){
				uni.showToast({
					icon:'none',
					title:"请选择期望薪资"
				})
				return;
			}
			delete this.jobDetail.industryList;				
			if(!this.expJobId){
				//新增
				this.jobDetail.resumeId = this.resumeId
				let res=await this.$apis.addJobsInfo(this.jobDetail);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}				
			}else{
				//修改
				let res = await this.$apis.eidthJobsInfo(this.jobDetail);
				if(res){
					uni.navigateBack({
						delta:1
					})
				}
			}
			
		},
		//删除
		async remove(expJobId){			
			let res = await this.$apis.detelJobsInfo(expJobId);
			if(res){
				uni.navigateBack({
					delta:1
				})
			}
			
		}
	}
};
</script>

<style lang="scss" scoped>
	input{
		width: 80%;
	}
.input-group {
	border-radius: 10upx;
	margin-top: 10upx;
	overflow: hidden;
}

.input-row {
	display: flex;
	flex-direction: row;
	position: relative;
	background: #fff;
	justify-content: space-between;
	align-items: center;
	padding: 15upx 10upx;
}

.input-row .title {
	width: 25%;
	padding: 20upx 0;
	padding-left: 20upx;
	line-height: 50upx;
	font-size: 28rpx;
}

.border-bottom-1px {
	position: relative;

	&::after {
		position: absolute;
		z-index: 1;
		right: 0;
		bottom: 0;
		left: 20upx;
		height: 1upx;
		content: '';
		-webkit-transform: scaleY(0.5);
		transform: scaleY(0.5);
		background-color: #e2e2e2;
	}
}

.header {
	display: flex;
	flex-direction: column;
	.tip {
		font-size:28rpx;
		color:#666;
		margin-left: 20upx;
	}
}

.head-img {
	margin-right: 15upx;
	image {
		width: 160upx;
		height: 160upx;
		border-radius: 50%;
	}
}

radio-group {
	margin-right: 10upx;
}

.radio {
	margin-left: 20upx;
}

.input-column {
	display: flex;
	flex-direction: column;
	background-color: #fff;
	padding: 30upx 20upx 10upx 20upx;

	.title {
		margin-left: 10upx;
		font-size: 28rpx;
	}

	.input-item {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
	}

	.picker {
		padding: 30upx 0;
		margin-left: 10upx;
		position: relative;
		picker {
			font-size: 28rpx;
			width: 100%;
			position: absolute;
		}
	}
	.yzb-next {
		float: right;
		color: #999;
	}
}

.content {
	background: #fff;
}

.btn-row {
	position: fixed;
	bottom: 20upx;
	width: 100%;
	box-sizing: border-box;
	background-color: #FFFFFF;
	padding-bottom: constant(safe-area-inset-bottom);
	padding-bottom: env(safe-area-inset-bottom);
	box-sizing: content-box;	
	.btn-delete{
		background-color:#ccc;
		height: 90upx;
		line-height: 90upx;
		font-size: 34rpx;
		color: #333;
		width: 50%;
	}
	
	.btn-save{
		background-color: #84C0F4;
		height: 90upx;
		line-height: 90upx;
		font-size: 34rpx;
	}
	.width-55{
		width: 50%;
	}
	
	.width-90{
		width: 90%;
		display: block;
		margin: 0 auto;
	}
}
</style>
